#include "send_xml_impl.h"


void network::send_xml_impl::create_open_object(const string &name)
{
	_attrib.clear();
	_is_single = false;
	_header = name;
}

void network::send_xml_impl::create_close_object(const string &name)
{
	_is_single = false;
	_footer = name;
}

void network::send_xml_impl::create_single_object(const string &name)
{
	_is_single = true;
	_footer = "";
	_header = name; 
}

void network::send_xml_impl::create_attrib(const string &name, const string &v)
{
	_attrib.push_back(std::make_pair(name, v));
}

const string& network::send_xml_impl::get_header() const
{
	// parsing the attribs...
	string line;
	typedef list<std::pair<string, string> >::const_iterator c_it;
	for(c_it i = _attrib.begin();
	    i != _attrib.end(); ++i) {
		line += i->first + "=\"";
		line += i->second + "\" ";
	}
	_all = "<" + _header + " " + line + ((_is_single) ? "/>" : ">");
	return _all;
}

const string& network::send_xml_impl::get_footer() const
{
	if(_is_single) {
		_all = "";
		return _all;
	}
	_all = "</" + _footer + ">";
	return _all;
}

boost::shared_ptr<network::send_impl> network::send_xml_impl::clone() const
{
	return boost::shared_ptr<network::send_impl>(new send_xml_impl());
}


